package com.loongtech.bi.support;

import java.util.ArrayList;
import java.util.List;

public class RoleSchoolInfo {
	private String schoolKey;
	private String schoolName;
	private long schoolCount;

	/**
	 * 数据库表EntityRoleSchoolDistribute中取出的roleSchoolInfos字段（字符串）转化成可被前端显示的List
	 * @param str
	 * @return
	 */
	public static List<RoleSchoolInfo> schoolInfosString2List(String str) {
		List<RoleSchoolInfo> result = new ArrayList<RoleSchoolInfo>();
		
		String[] kvs = str.split(",");
		for (String kv : kvs) {
			String[] tmp = kv.split(":");
			
			if (tmp == null || tmp.length != 2) {
				continue;
			}
			
			RoleSchoolInfo rsi = new RoleSchoolInfo();
			rsi.setSchoolKey(tmp[0]);
			rsi.setSchoolName("职业" + tmp[0]);  // TODO，以后可能读枚举或表
			rsi.setSchoolCount(Long.parseLong(tmp[1]));
			
			result.add(rsi);
		}
		
		return result;
	}
	
	/**
	 * 向数据库表EntityRoleSchoolDistribute中的roleSchoolInfos字段追加记录
	 * @param schoolInfos 数据库中已有的内容
	 * @param school  职业
	 * @param count 数量
	 * @return
	 */
	public static String addSchoolInfosString(String schoolInfos, String school, Long count) {
		String result = school + ":" + count;
		
		if (schoolInfos != null && !"".equals(schoolInfos)) {
			result = schoolInfos + "," + (school + ":" + count);
		}
		
		return result;
	}
	
	/*public static String schoolInfosList2String(List<RoleSchoolInfo> list) {
		StringBuffer result = new StringBuffer();
		
		return result.toString();
	}*/
	
	public String getSchoolKey() {
		return schoolKey;
	}

	public void setSchoolKey(String schoolKey) {
		this.schoolKey = schoolKey;
	}

	public String getSchoolName() {
		return schoolName;
	}

	public void setSchoolName(String schoolName) {
		this.schoolName = schoolName;
	}

	public long getSchoolCount() {
		return schoolCount;
	}

	public void setSchoolCount(long schoolCount) {
		this.schoolCount = schoolCount;
	}

}
